package com.xzm.service.impl;

import com.xzm.dao.IAccountDao;
import com.xzm.domain.Account;
import com.xzm.service.IAccountService;
import com.xzm.utils.TransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 3052
 * @create 2020-07-28 16:17
 *
 *          事务控制都是在业务层中
 */
@Service("accountService")
public class AccountServiceImpl implements IAccountService {

    @Autowired//可以不需要set方法
    private IAccountDao accountDao;

    public List<Account> findAllAccount() {
        return accountDao.findAllAccount();
    }

    public Account findAccountById(Integer accoutId) {
        return accountDao.findAccountById(accoutId);
    }

    public void updateAccount(Account account) {
        accountDao.updateAccount(account);
    }

    public void saveAccount(Account account) {
        accountDao.saveAccount(account);
    }

    public void deleteAccount(Integer accountId) {
        accountDao.deleteAccount(accountId);
    }

    public void transfer(String sourceName, String targetName, Integer money) {
        System.out.println("transfer....");
        Account source = accountDao.findAccountByName(sourceName);
        Account target = accountDao.findAccountByName(targetName);
        source.setMoney(source.getMoney()-money);
        target.setMoney(target.getMoney()+money);
        accountDao.updateAccount(source);
        //int i=1/0;
        accountDao.updateAccount(target);
    }

    //他只是连接点，不是切入点，因为他没有被增强
    public void test(){

    }
}
